class Game_Party < Game_Unit

  #庄园随从配置
  def get_guanjia
    if @guanjian == nil
      @guanjian = Guanjia.new(1)
    end
    return @guanjian
  end

  def set_new_guanjia(guanjia)
    @guanjian = guanjia
  end

  def get_yahuan
    return @yahuan
  end

  def set_new_yahuan(yahuan)
    #配置丫鬟的开关
    if yahuan != nil
      $game_switches[601] = true
      @yahuan = yahuan
      $game_party.set_spin_level(@yahuan.fengren / 10)
    else
      $game_switches[601] = false
      @yahuan = yahuan
      $game_party.set_spin_level(0)
    end
  end

  def get_chushi
    return @chushi
  end

  def set_new_chushi(chushi)
    #配置厨师的开关
    if chushi != nil
      $game_switches[602] = true
    else
      $game_switches[602] = false
    end
    cook_recipe = CookRecipe.new
    all_recipe = cook_recipe.getRecipe
    #清除原有厨师会的菜谱
    if @chushi != nil
      recipe_list = @chushi.recipy
      if recipe_list != nil
        recipe_list.each do |recipe_id|
          all_recipe.each do |a_recipe|
            if a_recipe["id"] == recipe_id
              $game_variables[a_recipe["switch"]] = 0
            end
          end
        end
      end
    end

    @chushi = chushi
    #开启新厨师会的菜谱
    if @chushi != nil
      recipe_list = @chushi.recipy
      if recipe_list != nil
        recipe_list.each do |recipe_id|
          all_recipe.each do |a_recipe|
            if a_recipe["id"] == recipe_id
              $game_variables[a_recipe["switch"]] = 1
            end
          end
        end
      end
      $game_party.set_cook_level(@chushi.chuyi / 10)
    else
      $game_party.set_cook_level(0)
    end


  end

  def get_xiaren
    return @xiaren
  end

  def set_new_xiaren(xiaren)
    #配置下人的开关
    if xiaren != nil
      $game_switches[603] = true
    else
      $game_switches[603] = false
    end
    @xiaren = xiaren
  end

  def get_tiejiang
    return @tiejiang
  end

  def set_new_tiejiang(tiejiang)
    #配置铁匠的开关
    @tiejiang = tiejiang
    if tiejiang != nil
      $game_switches[604] = true
      $game_party.set_forge_level(@tiejiang.duanzao / 10)
    else
      $game_switches[604] = false
      $game_party.set_forge_level(0)
    end
  end

  def get_shouwei
    return @shouwei
  end

  def set_new_shouwei(shouwei)
    #配置守卫的开关
    if shouwei != nil
      $game_switches[605] = true
    else
      $game_switches[605] = false
    end
    @shouwei = shouwei
  end

  def suicong_leave
    if get_xiaren != nil
      self.set_new_xiaren(nil)
      return
    end
    if get_chushi != nil
      self.set_new_chushi(nil)
      return
    end
    if get_tiejiang != nil
      self.set_new_tiejiang(nil)
      return
    end
    if get_shouwei != nil
      self.set_new_shouwei(nil)
      return
    end
    if get_yahuan != nil
      self.set_new_yahuan(nil)
      return
    end
  end

  #庄园资金
  def get_zhuangyuan_gold
    if @zhuangyuan_gold == nil
      @zhuangyuan_gold = 0
    end
    return @zhuangyuan_gold
  end

  def set_zhuangyuan_gold(new_param)
    @zhuangyuan_gold = new_param
  end

  def gain_zhuangyuan_gold(new_param)
    current_gold = self.get_zhuangyuan_gold
    @zhuangyuan_gold = current_gold + new_param
  end

  #庄园支付工资时间记录
  def get_pay_time
    if @pay_time == nil
      @pay_time = [$game_time.year, $game_time.month]
    end
    return @pay_time
  end

  def set_pay_time(pay_year, pay_month)
    @pay_time = [pay_year, pay_month]
  end

end

#随从公共类
class Suicong_Base
  def initialize
    @task_list = []
    @state = "normal"
  end

  def id
    return @id
  end

  def name
    return @name
  end

  def pic
    return @pic
  end

  def note
    return @note
  end

  def ability1
    return @ability1
  end

  def ability2
    return @ability2
  end

  def ability3
    return @ability3
  end

  def tili
    return 1
  end

  def current_tili
    return 1
  end

  def cost_per_month
    return (@ability1 + @ability2 + @ability3) * 10
  end

  def busy?
    if @task_list.length > 0
      return true
    else
      return false
    end
  end

  def task_list
    return @task_list
  end

  def add_task(task)
    @task_list.push(task)
  end

end


#守卫类
class Shouwei < Suicong_Base
  def initialize(id)
    super()
    if id <= 0
      getRandShouwei
    else
      getShouwei(id)
    end

    @current_tili = self.tili
  end

  def getShouwei(id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    shouweiModuleList = estateModule["守卫"]
    @shouweiModule = shouweiModuleList[0]
    shouweiModuleList.each do |myModule|
      if myModule["id"] == id
        @shouweiModule = myModule
      end
    end
    @id = @shouweiModule["id"]
    @name = @shouweiModule["name"]
    @pic = @shouweiModule["pic"]
    @note = @shouweiModule["note"]
    set_shouhu(@shouweiModule["守护"])
    set_yongwu(@shouweiModule["勇武"])
    set_tili(@shouweiModule["体力"])
  end

  def getRandShouwei
    #生成守卫图片
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    picList = estateModule["shouwei_pic_list"]
    @pic = picList[rand(picList.length)]
    #守卫id
    @id = 0
    #守卫姓名
    last_names = MyName.last_names
    last_name = last_names[rand(last_names.length)]
    first_name = ""
    if rand(10) < 5
      first_names = MyName.male_first_name1
      first_name = first_names[rand(first_names.length)]
    else
      first_names = MyName.male_first_name2
      first_name = first_names[rand(first_names.length)]
    end
    @name = last_name+first_name

    #根据管家能力，生成守卫能力
    guanjia = $game_party.get_guanjia
    set_shouhu(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_yongwu(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_tili(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)

    yongqi_string = ""
    if yongwu < 30
      yongqi_string += "胆小怯懦，"
    elsif yongwu < 60
      yongqi_string += "略有胆识，"
    elsif yongwu < 90
      yongqi_string += "胆识过人，"
    else
      yongqi_string += "勇武无双，"
    end

    wuyi_string = ""
    if shouhu < 30
      wuyi_string += "手无缚鸡之力。"
    elsif shouhu < 60
      wuyi_string += "略通拳脚。"
    elsif shouhu < 90
      wuyi_string += "武艺超群。"
    else
      wuyi_string += "身怀绝世武艺，技惊四座。"
    end

    @note = "于"+GameTime.year_name+"年"+GameTime.month_name+GameTime.day_name+"日遇到"+@name+","+"此人" + yongqi_string + wuyi_string
  end

  def current_tili
    if @current_tili == nil
      @current_tili = 0
    end
    return @current_tili
  end

  def shouhu
    return @ability1
  end

  def yongwu
    return @ability2
  end

  def tili
    return @ability3
  end

  def set_shouhu(new_param)
    @ability1 = new_param
  end

  def set_yongwu(new_param)
    @ability2 = new_param
  end

  def set_tili(new_param)
    @ability3 = new_param
  end

end

#铁匠类
class Tiejiang < Suicong_Base
  def initialize(id)
    super()
    if id <= 0
      getRandTiejiang
    else
      getTiejiang(id)
    end

    @current_tili = self.tili
  end

  def getTiejiang(id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    tiejiangModuleList = estateModule["铁匠"]
    @tiejiangModule = tiejiangModuleList[0]
    tiejiangModuleList.each do |myModule|
      if myModule["id"] == id
        @tiejiangModule = myModule
      end
    end
    @id = @tiejiangModule["id"]
    @name = @tiejiangModule["name"]
    @pic = @tiejiangModule["pic"]
    @note = @tiejiangModule["note"]
    set_duanzao(@tiejiangModule["锻造"])
    set_shiyun(@tiejiangModule["时运"])
    set_tili(@tiejiangModule["体力"])
    if @tiejiangModule["recipy"] != nil
      @recipy = @tiejiangModule["recipy"]
    else
      @recipy = []
    end

  end

  def getRandTiejiang
    #生成铁匠图片
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    picList = estateModule["tiejiang_pic_list"]
    @pic = picList[rand(picList.length)]
    #铁匠id
    @id = 0
    #铁匠姓名
    last_names = MyName.last_names
    last_name = last_names[rand(last_names.length)]
    first_name = ""
    if rand(10) < 5
      first_names = MyName.male_first_name1
      first_name = first_names[rand(first_names.length)]
    else
      first_names = MyName.male_first_name2
      first_name = first_names[rand(first_names.length)]
    end
    @name = last_name+first_name

    #根据管家能力，生成铁匠能力
    guanjia = $game_party.get_guanjia
    set_duanzao(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_shiyun(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_tili(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)

    @note = ""

    shiyun_string = ""
    if shiyun < 30
      shiyun_string += "华盖压顶，厄运缠身，"
    elsif shiyun < 60
      shiyun_string += "眉间隐有黑气，愁云惨淡，"
    elsif shiyun < 90
      shiyun_string += "印堂明亮，百事亨通，"
    else
      shiyun_string += "紫气隐绕，鸿运灌顶，"
    end

    duanzao_string = ""
    if duanzao < 30
      duanzao_string += "锻造技艺粗浅。"
    elsif duanzao < 60
      duanzao_string += "略通锻造。"
    elsif duanzao < 90
      duanzao_string += "精通锻造此道。"
    else
      duanzao_string += "锻造技艺炉火纯青。"
    end

    @note = "于"+GameTime.year_name+"年"+GameTime.month_name+GameTime.day_name+"日遇到"+@name+","+"此人" + shiyun_string + duanzao_string

  end

  def current_tili
    if @current_tili == nil
      @current_tili = 0
    end
    return @current_tili
  end

  def duanzao
    return @ability1
  end

  def shiyun
    return @ability2
  end

  def tili
    return @ability3
  end

  def set_duanzao(new_param)
    @ability1 = new_param
  end

  def set_shiyun(new_param)
    @ability2 = new_param
  end

  def set_tili(new_param)
    @ability3 = new_param
  end
end

#下人类
class Xiaren < Suicong_Base
  def initialize(id)
    super()
    if id <= 0
      getRandXiaren
    else
      getXiaren(id)
    end

    @current_tili = self.tili
  end

  def getXiaren(id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    xiarenModuleList = estateModule["下人"]
    @xiarenModule = xiarenModuleList[0]
    xiarenModuleList.each do |myModule|
      if myModule["id"] == id
        @xiarenModule = myModule
      end
    end
    @id = @xiarenModule["id"]
    @name = @xiarenModule["name"]
    @pic = @xiarenModule["pic"]
    @note = @xiarenModule["note"]
    set_caimai(@xiarenModule["采买"])
    set_qinlao(@xiarenModule["勤劳"])
    set_tili(@xiarenModule["体力"])
  end

  def getRandXiaren
    #生成下人图片
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    picList = estateModule["xiaren_pic_list"]
    @pic = picList[rand(picList.length)]
    #下人id
    @id = 0
    #下人姓名
    last_names = MyName.last_names
    last_name = last_names[rand(last_names.length)]
    first_name = ""
    if rand(10) < 5
      first_names = MyName.male_first_name1
      first_name = first_names[rand(first_names.length)]
    else
      first_names = MyName.male_first_name2
      first_name = first_names[rand(first_names.length)]
    end
    @name = last_name+first_name

    #根据管家能力，生成下人能力
    guanjia = $game_party.get_guanjia
    set_caimai(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_qinlao(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_tili(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)

    @note = ""

    qinlao_string = ""
    if qinlao < 30
      qinlao_string += "好吃懒做，好逸恶劳，"
    elsif qinlao < 60
      qinlao_string += "偶尔帮忙生计，"
    elsif qinlao < 90
      qinlao_string += "勤快干练，"
    else
      qinlao_string += "不辞辛苦，任劳任怨，"
    end

    caimai_string = ""
    if caimai < 30
      caimai_string += "口笨嘴拙，常常出口伤人。"
    elsif caimai < 60
      caimai_string += "与人沟通顺畅，能够正常表达自己的目的。"
    elsif caimai < 90
      caimai_string += "巧舌如簧，常常辩的人无法还口。"
    else
      caimai_string += "铁齿铜牙，一口伶牙俐齿外号【鬼见愁】。"
    end

    @note = "于"+GameTime.year_name+"年"+GameTime.month_name+GameTime.day_name+"日遇到"+@name+","+"此人" + qinlao_string + caimai_string
  end

  def current_tili
    if @current_tili == nil
      @current_tili = 0
    end
    return @current_tili
  end

  def caimai
    return @ability1
  end

  def qinlao
    return @ability2
  end

  def tili
    return @ability3
  end

  def set_caimai(new_param)
    @ability1 = new_param
  end

  def set_qinlao(new_param)
    @ability2 = new_param
  end

  def set_tili(new_param)
    @ability3 = new_param
  end

end

#厨师类
class Chushi < Suicong_Base
  def initialize(id)
    super()
    if id <= 0
      getRandChushi
    else
      getChshi(id)
    end

    @current_tili = self.tili
  end

  def getChshi(id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    chushiModuleList = estateModule["厨师"]
    @chushiModule = chushiModuleList[0]
    chushiModuleList.each do |myModule|
      if myModule["id"] == id
        @chushiModule = myModule
      end
    end
    @id = @chushiModule["id"]
    @name = @chushiModule["name"]
    @pic = @chushiModule["pic"]
    @note = @chushiModule["note"]
    set_chuyi(@chushiModule["厨艺"])
    set_yueli(@chushiModule["阅历"])
    set_tili(@chushiModule["体力"])
    if @chushiModule["recipy"] != nil
      @recipy = @chushiModule["recipy"]
    else
      @recipy = []
    end
  end

  def getRandChushi
    #生成厨师图片
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    picList = estateModule["chushi_pic_list"]
    @pic = picList[rand(picList.length)]
    #厨师id
    @id = 0
    #厨师姓名
    last_names = MyName.last_names
    last_name = last_names[rand(last_names.length)]
    first_name = ""
    if rand(10) < 5
      first_names = MyName.male_first_name1
      first_name = first_names[rand(first_names.length)]
    else
      first_names = MyName.male_first_name2
      first_name = first_names[rand(first_names.length)]
    end
    @name = last_name+first_name

    #根据管家能力，生成厨师能力
    guanjia = $game_party.get_guanjia
    set_chuyi(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_yueli(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_tili(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    #获取随机生成厨师的菜谱
    init_recipy

    @note = ""

    yueli_string = ""
    if yueli < 30
      yueli_string += "见识浅陋，"
    elsif yueli < 60
      yueli_string += "见识有限，"
    elsif yueli < 90
      yueli_string += "见识宽广，各大菜系都有所涉猎，"
    else
      yueli_string += "见识广博，尝遍天下美食，"
    end

    chuyi_string = ""
    if chuyi < 30
      chuyi_string += "黑暗料理的代言人。。。"
    elsif chuyi < 60
      chuyi_string += "但熟悉家常菜的做法。"
    elsif chuyi < 90
      chuyi_string += "厨艺超群。"
    else
      chuyi_string += "厨艺天下闻名。"
    end

    @note = "于"+GameTime.year_name+"年"+GameTime.month_name+GameTime.day_name+"日遇到"+@name+","+"此人" + yueli_string + chuyi_string
  end

  #生成随机生成厨师的菜谱
  def init_recipy
    @recipy = []
    cook_recipe = CookRecipe.new
    all_recipe = cook_recipe.getRecipe
    for i in 0..2
      recipe_index = rand(all_recipe.length)
      @recipy.push(all_recipe[recipe_index]["id"])
      all_recipe.delete_at(recipe_index)
    end
  end

  def current_tili
    if @current_tili == nil
      @current_tili = 0
    end
    return @current_tili
  end

  def recipy
    return @recipy
  end

  def chuyi
    return @ability1
  end

  def yueli
    return @ability2
  end

  def tili
    return @ability3
  end

  def set_chuyi(new_param)
    @ability1 = new_param
  end

  def set_yueli(new_param)
    @ability2 = new_param
  end

  def set_tili(new_param)
    @ability3 = new_param
  end

end

#丫鬟类
class Yahuan < Suicong_Base
  def initialize(id)
    super()
    if id <= 0
      getRandYahuan
    else
      getYanhuan(id)
    end

    @current_tili = self.tili
  end

  def getYanhuan(id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    yahuanModuleList = estateModule["丫鬟"]
    @yahuanModule = yahuanModuleList[0]
    yahuanModuleList.each do |myModule|
      if myModule["id"] == id
        @yahuanModule = myModule
      end
    end
    @id = @yahuanModule["id"]
    @name = @yahuanModule["name"]
    @pic = @yahuanModule["pic"]
    @note = @yahuanModule["note"]
    set_cihou(@yahuanModule["伺候"])
    set_tili(@yahuanModule["体力"])
    set_fengren(@yahuanModule["缝纫"])
    if @yahuanModule["recipy"] != nil
      @recipy = @yahuanModule["recipy"]
    else
      @recipy = []
    end
  end

  def getRandYahuan
    #生成丫鬟图片
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    picList = estateModule["yahuan_pic_list"]
    @pic = picList[rand(picList.length)]
    #丫鬟id
    @id = 0
    #丫鬟姓名
    last_names = MyName.last_names
    last_name = last_names[rand(last_names.length)]
    first_name = ""
    if rand(10) < 5
      first_names = MyName.female_first_name1
      first_name = first_names[rand(first_names.length)]
    else
      first_names = MyName.female_first_name2
      first_name = first_names[rand(first_names.length)]
    end
    @name = last_name+first_name

    #根据管家能力，生成丫鬟能力
    guanjia = $game_party.get_guanjia
    set_cihou(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_tili(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)
    set_fengren(guanjia.yanguang / 2 + rand(guanjia.yunqi) / 2)

    @note = ""

    cihou_string = ""
    if cihou < 30
      cihou_string += "最笨口拙，常常弄砸事情，"
    elsif cihou < 60
      cihou_string += "善良体贴，"
    elsif cihou < 90
      cihou_string += "聪明伶俐，温婉可人，"
    else
      cihou_string += "与你心有灵犀，对你柔情似水，"
    end

    fengren_string = ""
    if fengren < 30
      fengren_string += "丝毫不动女红。"
    elsif fengren < 60
      fengren_string += "略懂女红。"
    elsif fengren < 90
      fengren_string += "精通女红技艺。"
    else
      fengren_string += "女红技艺出神入化。"
    end

    @note = "于"+GameTime.year_name+"年"+GameTime.month_name+GameTime.day_name+"日遇到"+@name+","+"此人" + cihou_string + fengren_string
  end

  def current_tili
    if @current_tili == nil
      @current_tili = 0
    end
    return @current_tili
  end

  def cihou
    return @ability1
  end

  def tili
    return @ability2
  end

  def fengren
    return @ability3
  end

  def set_cihou(new_param)
    @ability1 = new_param
  end

  def set_tili(new_param)
    @ability2 = new_param
  end

  def set_fengren(new_param)
    @ability3 = new_param
  end
end

#管家类
class Guanjia < Suicong_Base
  def initialize(id)
    super()
    initGuanjiaModule
    @id = @guanjiaModule["id"]
    @name = @guanjiaModule["name"]
    @pic = @guanjiaModule["pic"]
    @note = @guanjiaModule["note"]
    set_yueli(@guanjiaModule["阅历"])
    set_yanguang(@guanjiaModule["眼光"])
    set_yunqi(@guanjiaModule["运气"])
  end

  def initGuanjiaModule
    guanjiaList = getGuanjiaModule
    @guanjiaModule = guanjiaList[0]
    guanjiaList.each do |myModule|
      if myModule["id"] == id
        @guanjiaModule = myModule
      end
    end
  end

  def getGuanjiaModule
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    return estateModule["管家"]
  end

  def set_yueli(new_param)
    @ability1 = new_param
  end

  def set_yanguang(new_param)
    @ability2 = new_param
  end

  def set_yunqi(new_param)
    @ability3 = new_param
  end

  def yueli
    return @ability1
  end

  def yanguang
    return @ability2
  end

  def yunqi
    return @ability3
  end

  #获取每月需要支付的工资数
  def zhuangyuan_pay_per_month
    result = 0
    yahuan = $game_party.get_yahuan
    chushi = $game_party.get_chushi
    xiaren = $game_party.get_xiaren
    tiejiang = $game_party.get_tiejiang
    shouwei = $game_party.get_shouwei
    result += yahuan.cost_per_month if yahuan != nil
    result += chushi.cost_per_month if chushi != nil
    result += xiaren.cost_per_month if xiaren != nil
    result += tiejiang.cost_per_month if tiejiang != nil
    result += shouwei.cost_per_month if shouwei != nil
    return result
  end

  #支付每月工资
  def pay_wages
    now_year = $game_time.year
    now_month = $game_time.month
    now_month_total = now_year * 12 + now_month
    pay_year = $game_party.get_pay_time[0]
    pay_month = $game_party.get_pay_time[1]
    pay_month_total = pay_year * 12 + pay_month
    delta_month = now_month_total - pay_month_total
    if delta_month < 0
      $game_party.set_pay_time(now_year,now_month)
    elsif delta_month > 0
      for i in 0..delta_month - 1
        $game_party.set_pay_time(now_year,now_month)
        if $game_party.get_zhuangyuan_gold - self.zhuangyuan_pay_per_month < 0
          $game_party.set_zhuangyuan_gold(0)
          #无法支付工资，随从离开
          $game_party.suicong_leave
        else
          $game_party.gain_zhuangyuan_gold(0 - self.zhuangyuan_pay_per_month)
        end
      end
    end
  end

end

#随从任务类
class Suicong_Task
  def initialize(task_id, suicong)
    @task_module = get_modlue_from_id(task_id)
    @suicong = suicong
    init_task_param(@task_module, suicong)
    @start_time = [$game_time.year,$game_time.month,$game_time.day]
  end

  def init_task_param(task_module, suicong)
    @id = task_module["id"]
    @name = task_module["name"]
    origin_time_cost = task_module["time_cost"]
    origin_tili_cost = task_module["tili_cost"]
    @need_guard = task_module["need_guard"]
    @type = task_module["type"]

    if origin_time_cost == nil
      @time_cost = 0
    else
      if @need_guard
        @time_cost = origin_time_cost * 100 / ($game_party.get_shouwei.yongwu * 50 / 100 + 100)
      else
        @time_cost = origin_time_cost
      end
    end

    if origin_tili_cost == nil
      @tili_cost = 0
    else
      if @need_guard
        @tili_cost = origin_tili_cost * 100 / ($game_party.get_shouwei.yongwu * 50 / 100 + 100)
      else
        @tili_cost = origin_tili_cost
      end
    end
  end

  def get_modlue_from_id(task_id)
    estateFilePath = "Data/Estate.txt"
    estateFile = File.new(estateFilePath)
    estateString = ""
    estateFile.readlines.each do |line|
      estateString += line
    end
    estateFile.close
    estateModule = eval estateString
    task_list = estateModule["task"]
    task_list.each do |a_task|
      if a_task["id"] == task_id
        return a_task
      end
    end
    return nil
  end

  def id
    return @id
  end

  def name
    return @name
  end

  def time_cost
    return @time_cost
  end

  def tili_cost
    return @tili_cost
  end

  def need_grard
    return @need_guard
  end

  def type
    return @type
  end

  def suicong
    return @suicong
  end

  def start_time
    return @start_time
  end
end
#锻造任务
class Duanzao_Task < Suicong_Task
  def initialize(task_id, suicong, duanzao_id, duanzao_type)
    super(task_id, suicong)
    @duanzao_module = get_duanzao_module_from_id(duanzao_id, duanzao_type)
    init_task_param(@task_module,suicong,@duanzao_module)
  end

  def get_duanzao_module_from_id(duanzao_id, duanzao_type)
    recipeFilePath = "Data/ForgeRecipe_Armor.txt"
    if duanzao_type.eql?("weapon")
      recipeFilePath = "Data/ForgeRecipe_Weapon.txt"
    else
      recipeFilePath = "Data/ForgeRecipe_Armor.txt"
    end
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == duanzao_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,duanzao_module)
    origin_time_cost = duanzao_module["time_cost"] == nil ? 1 :  duanzao_module["time_cost"]
    origin_tili_cost = duanzao_module["tili_cost"] == nil ? 1 :  duanzao_module["tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.duanzao + 1000)
    @time_cost = origin_time_cost * 100 / (suicong.duanzao + 1000)
  end

  def duanzao_module
    return @duanzao_module
  end
end
#裁缝任务
class Caifeng_Task < Suicong_Task
  def initialize(task_id, suicong, caifeng_id, caifeng_type)
    super(task_id, suicong)
    @caifeng_module = get_caifeng_module_from_id(caifeng_id, caifeng_type)
    init_task_param(@task_module,suicong,@caifeng_module)
  end

  def get_caifeng_module_from_id(caifeng_id, caifeng_type)
    recipeFilePath = "Data/SpinRecipe_Armor.txt"
    if caifeng_type.eql?("weapon")
      recipeFilePath = "Data/SpinRecipe_Weapon.txt"
    else
      recipeFilePath = "Data/SpinRecipe_Armor.txt"
    end
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == caifeng_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,caifeng_module)
    origin_time_cost = caifeng_module["time_cost"] == nil ? 1 :  caifeng_module["time_cost"]
    origin_tili_cost = caifeng_module["tili_cost"] == nil ? 1 :  caifeng_module["tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.fengren + 1000)
    @time_cost = origin_time_cost * 100 / (suicong.fengren + 1000)
  end

  def caifeng_module
    return @caifeng_module
  end
end
#下厨任务
class Xiachu_Task < Suicong_Task
  def initialize(task_id, suicong, xiachu_id)
    super(task_id, suicong)
    @xiachu_module = get_xiachu_module_from_id(xiachu_id)
    init_task_param(@task_module,suicong,@xiachu_module)
  end

  def get_xiachu_module_from_id(xiachu_id)
    recipeFilePath = "Data/CookRecipe.txt"
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == xiachu_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,xiachu_module)
    origin_time_cost = xiachu_module["time_cost"] == nil ? 1 :  xiachu_module["time_cost"]
    origin_tili_cost = xiachu_module["tili_cost"] == nil ? 1 :  xiachu_module["tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.chuyi + 1000)
    @time_cost = origin_time_cost * 100 / (suicong.chuyi + 1000)
  end

  def xiachu_module
    return @xiachu_module
  end
end
#招贤任务
class Zhaoxian_Task < Suicong_Task
  def initialize(task_id, suicong, guard)
    super(task_id, suicong)
    init_task_param(guard);
  end

  def init_task_param(guard)
    if guard
      @time_cost /= 2
      @tili_cost /= 2
    end
  end

end
#学习菜谱
class LearnRecipe_Task < Suicong_Task
  def initialize(task_id, suicong, recipe_id)
    super(task_id, suicong)
    @recipe_module = get_recipe_module_from_id(recipe_id)
    init_task_param(@task_module,suicong,@recipe_module)
  end

  def get_recipe_module_from_id(recipe_id)
    recipeFilePath = "Data/CookRecipe.txt"
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == recipe_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,recipe_module)
    origin_time_cost = recipe_module["learn_time_cost"] == nil ? 1 :  recipe_module["learn_time_cost"]
    origin_tili_cost = recipe_module["learn_tili_cost"] == nil ? 1 :  recipe_module["learn_tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.yueli + 100)
    @time_cost = origin_time_cost * 100 / (suicong.yueli + 100)
  end

  def recipe_module
    return @recipe_module
  end
end
#采买任务
class Caimai_Task < Suicong_Task
  def initialize(task_id, suicong, recipe_id, purchase_item_list, guard)
    super(task_id, suicong)
    @recipe_module = get_recipe_module_from_id(recipe_id)
    init_task_param(@task_module,suicong,@recipe_module,purchase_item_list, guard)
  end

  def get_recipe_module_from_id(recipe_id)
    recipeFilePath = "Data/CaimaiRecipe.txt"
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == recipe_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,recipe_module,purchase_item_list, guard)
    origin_time_cost = 0
    origin_tili_cost = 0
    recipe_list = recipe_module["recipe"]
    purchase_item_list.each do |purchase_item|
      recipe_list.each do |recipe_item|
        if purchase_item.id == recipe_item["id"]
          origin_time_cost += recipe_item["time_cost"] * purchase_item.num
          origin_tili_cost += recipe_item["tili_cost"] * purchase_item.num
        end
      end
    end

    @tili_cost = origin_tili_cost * 100 / (suicong.caimai + 100)
    @time_cost = origin_time_cost * 100 / (suicong.caimai + 100)

    if guard
      @tili_cost /= 2
      @time_cost /= 2
    end
  end

  def recipe_module
    return @recipe_module
  end
end

class Purchase_Item
  def initialize(type,id,num)
    @type = type
    @id = id
    @num = num
  end

  def type
    return @type
  end

  def id
    return @id
  end

  def num
    return @num
  end
end
#种植任务
class Plant_Task < Suicong_Task
  def initialize(task_id, suicong, recipe_id)
    super(task_id, suicong)
    @recipe_module = get_recipe_module_from_id(recipe_id)
    init_task_param(@task_module,suicong,@recipe_module)
  end

  def get_recipe_module_from_id(recipe_id)
    recipeFilePath = "Data/PlantRecipe.txt"
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == recipe_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,recipe_module)
    origin_time_cost = recipe_module["time_cost"] == nil ? 1 :  recipe_module["time_cost"]
    origin_tili_cost = recipe_module["tili_cost"] == nil ? 1 :  recipe_module["tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.qinlao + 100)
    @time_cost = origin_time_cost * 100 / (suicong.qinlao + 100)
    @num = xiachu_module["num"] == nil ? 1 :  recipe_module["num"]
  end

  def num
    return @num
  end
end
#挖矿任务
class Mine_Task < Suicong_Task
  def initialize(task_id, suicong, recipe_id)
    super(task_id, suicong)
    @recipe_module = get_recipe_module_from_id(recipe_id)
    init_task_param(@task_module,suicong,@recipe_module)
  end

  def get_recipe_module_from_id(recipe_id)
    recipeFilePath = "Data/MineRecipe.txt"
    recipeFile = File.new(recipeFilePath)
    recipeString = ""
    recipeFile.readlines.each do |line|
      recipeString += line
    end
    recipeFile.close
    recipeModuleList = eval estateString
    recipeModuleList.each do |recipeModule|
      if recipeModule["id"] == recipe_id
        return recipeModule
      end
    end

    return nil
  end

  def init_task_param(task_module,suicong,recipe_module)
    origin_time_cost = recipe_module["time_cost"] == nil ? 1 :  recipe_module["time_cost"]
    origin_tili_cost = recipe_module["tili_cost"] == nil ? 1 :  recipe_module["tili_cost"]
    @tili_cost = origin_tili_cost * 100 / (suicong.qinlao + 100)
    @time_cost = origin_time_cost * 100 / (suicong.qinlao + 100)
    @num = xiachu_module["num"] == nil ? 1 :  recipe_module["num"]
  end

  def num
    return @num
  end
end

  module MyName
    def self.last_names
      my_last_names = [
          '赵','钱','孙','李','周','吴','郑','王',
          '冯','陈','楮','卫','蒋','沈','韩','杨',
          '朱','秦','尤','许','何','吕','施','张',
          '孔','曹','严','华','金','魏','陶','姜',
          '戚','谢','邹','喻','柏','水','窦','章',
          '云','苏','潘','葛','奚','范','彭','郎',
          '鲁','韦','昌','马','苗','凤','花','方',
          '俞','任','袁','柳','酆','鲍','史','唐',
          '费','廉','岑','薛','雷','贺','倪','汤',
          '滕','殷','罗','毕','郝','邬','安','常',
          '乐','于','时','傅','皮','卞','齐','康',
          '伍','余','元','卜','顾','孟','平','黄',
          '和','穆','萧','尹','姚','邵','湛','汪',
          '祁','毛','禹','狄','米','贝','明','臧',
          '计','伏','成','戴','谈','宋','茅','庞',
          '熊','纪','舒','屈','项','祝','董','梁',
          '杜','阮','蓝','闽','席','季','麻','强',
          '贾','路','娄','危','江','童','颜','郭',
          '梅','盛','林','刁','锺','徐','丘','骆',
          '高','夏','蔡','田','樊','胡','凌','霍',
          '虞','万','支','柯','昝','管','卢','莫',
          '经','房','裘','缪','干','解','应','宗',
          '丁','宣','贲','邓','郁','单','杭','洪',
          '包','诸','左','石','崔','吉','钮','龚',
          '程','嵇','邢','滑','裴','陆','荣','翁',
          '荀','羊','於','惠','甄','麹','家','封',
          '芮','羿','储','靳','汲','邴','糜','松',
          '井','段','富','巫','乌','焦','巴','弓',
          '牧','隗','山','谷','车','侯','宓','蓬',
          '全','郗','班','仰','秋','仲','伊','宫',
          '宁','仇','栾','暴','甘','斜','厉','戎',
          '祖','武','符','刘','景','詹','束','龙',
          '叶','幸','司','韶','郜','黎','蓟','薄',
          '印','宿','白','怀','蒲','邰','从','鄂',
          '索','咸','籍','赖','卓','蔺','屠','蒙',
          '池','乔','阴','郁','胥','能','苍','双',
          '闻','莘','党','翟','谭','贡','劳','逄',
          '姬','申','扶','堵','冉','宰','郦','雍',
          '郤','璩','桑','桂','濮','牛','寿','通',
          '边','扈','燕','冀','郏','浦','尚','农',
          '温','别','庄','晏','柴','瞿','阎','充',
          '慕','连','茹','习','宦','艾','鱼','容',
          '向','古','易','慎','戈','廖','庾','终',
          '暨','居','衡','步','都','耿','满','弘',
          '匡','国','文','寇','广','禄','阙','东',
          '欧','殳','沃','利','蔚','越','夔','隆',
          '师','巩','厍','聂','晁','勾','敖','融',
          '冷','訾','辛','阚','那','简','饶','空',
          '曾','毋','沙','乜','养','鞠','须','丰',
          '巢','关','蒯','相','查','后','荆','红',
          '游','竺','权','逑','盖','益','桓','公',
          '万俟','司马','上官','欧阳',
          '夏侯','诸葛','闻人','东方',
          '赫连','皇甫','尉迟','公羊',
          '澹台','公冶','宗政','濮阳',
          '淳于','单于','太叔','申屠',
          '公孙','仲孙','轩辕','令狐',
          '锺离','宇文','长孙','慕容',
          '鲜于','闾丘','司徒','司空',
          '丌官','司寇','仉督','子车',
          '颛孙','端木','巫马','公西',
          '漆雕','乐正','壤驷','公良',
          '拓拔','夹谷','宰父','谷梁',
          '晋','楚','阎','法','汝','鄢','涂','钦',
          '段干','百里','东郭','南门',
          '呼延','归海','羊舌','微生',
          '岳','帅','缑','亢','况','后','有','琴',
          '梁丘','左丘','东门','西门',
          '商','牟','佘','佴','伯','赏','南宫',
          '墨','哈','谯','笪','年','爱','阳','佟'
      ]
      return my_last_names
    end

    def self.male_first_name2
      first_names = [
          '嘉懿','煜城','懿轩','烨伟','苑博','伟泽','熠彤',
          '鸿煊','博涛','烨霖','烨华','煜祺','智宸','正豪',
          '昊然','明杰','立诚','立轩','立辉','峻熙','弘文',
          '熠彤','鸿煊','烨霖','哲瀚','鑫鹏','致远','俊驰',
          '雨泽','烨磊','晟睿','天佑','文昊','修洁','黎昕',
          '远航','旭尧','鸿涛','伟祺','荣轩','越泽','浩宇',
          '瑾瑜','皓轩','擎苍','擎宇','志泽','睿渊','楷瑞',
          '子轩','弘文','哲瀚','雨泽','鑫磊','修杰','伟诚',
          '建辉','晋鹏','天磊','绍辉','泽洋','明轩','健柏',
          '鹏煊','昊强','伟宸','博超','君浩','子骞','明辉',
          '鹏涛','炎彬','鹤轩','越彬','风华','靖琪','明诚',
          '高格','光华','国源','冠宇','晗昱','涵润','翰飞',
          '翰海','昊乾','浩博','和安','弘博','宏恺','鸿朗',
          '华奥','华灿','嘉慕','坚秉','建明','金鑫','锦程',
          '瑾瑜','晋鹏','经赋','景同','靖琪','君昊','俊明',
          '季同','开济','凯安','康成','乐语','力勤','良哲',
          '理群','茂彦','敏博','明达','朋义','彭泽','鹏举',
          '濮存','溥心','璞瑜','浦泽','奇邃','祺祥','荣轩',
          '锐达','睿慈','绍祺','圣杰','晟睿','思源','斯年',
          '泰宁','天佑','同巍','奕伟','祺温','文虹','向笛',
          '心远','欣德','新翰','兴言','星阑','修为','旭尧',
          '炫明','学真','雪风','雅昶','阳曦','烨熠','英韶',
          '永贞','咏德','宇寰','雨泽','玉韵','越彬','蕴和',
          '哲彦','振海','正志','子晋','自怡','德赫','君平'
      ]
      return first_names
    end

    def self.male_first_name1
      first_names = [
          '伟','刚','勇','毅','俊','峰','强','军','平',
          '保','东','文','辉','力','明','永','健','世',
          '广','志','义','兴','良','海','山','仁','波',
          '宁','贵','福','生','龙','元','全','国','胜',
          '学','祥','才','发','武','新','利','清','飞',
          '彬','富','顺','信','子','杰','涛','昌','成',
          '康','星','光','天','达','安','岩','中','茂',
          '进','林','有','坚','和','彪','博','诚','先',
          '敬','震','振','壮','会','思','群','豪','心',
          '邦','承','乐','绍','功','松','善','厚','庆',
          '磊','民','友','裕','河','哲','江','超','浩',
          '亮','政','谦','亨','奇','固','之','轮','翰',
          '朗','伯','宏','言','若','鸣','朋','斌','梁',
          '栋','维','启','克','伦','翔','旭','鹏','泽',
          '晨','辰','士','以','建','家','致','树','炎',
          '德','行','时','泰','盛','雄','琛','钧','冠',
          '策','腾','楠','榕','风','航','弘'
      ]
      return first_names
    end

    def self.female_first_name1
      first_names = [
          '秀','娟','英','华','慧','巧','美','娜','静',
          '淑','惠','珠','翠','雅','芝','玉','萍','红',
          '娥','玲','芬','芳','燕','彩','春','菊','兰',
          '凤','洁','梅','琳','素','云','莲','真','环',
          '雪','荣','爱','妹','霞','香','月','莺','媛',
          '艳','瑞','凡','佳','嘉','琼','勤','珍','贞',
          '莉','桂','娣','叶','璧','璐','娅','琦','晶',
          '妍','茜','秋','珊','莎','锦','黛','青','倩',
          '婷','姣','婉','娴','瑾','颖','露','瑶','怡',
          '婵','雁','蓓','纨','仪','荷','丹','蓉','眉',
          '君','琴','蕊','薇','菁','梦','岚','苑','婕',
          '馨','瑗','琰','韵','融','园','艺','咏','卿',
          '聪','澜','纯','毓','悦','昭','冰','爽','琬',
          '茗','羽','希','宁','欣','飘','育','滢','馥',
          '筠','柔','竹','霭','凝','晓','欢','霄','枫',
          '芸','菲','寒','伊','亚','宜','可','姬','舒',
          '影','荔','枝','思','丽'
      ]
      return first_names
    end

    def self.female_first_name2
      first_names = [
          '问萍','青蕾','雁云','芷枫','千旋','向梅','含蓝',
          '怀丝','梦文','幼芙','晓云','雨旋','秋安','雁风',
          '碧槐','从海','语雪','幼凡','秋卉','曼蕾','问蕾',
          '访兰','寄莲','紫绿','新雁','恨容','水柳','南云',
          '曼阳','幼蓝','忆巧','灵荷','怜兰','听曼','碧双',
          '忆雁','夜松','映莲','听曼','秋易','绿莲','宛秋',
          '雁安','问旋','以蓝','若亦','幻丝','山凡','南云',
          '寄蕊','绿春','思海','寄天','友秋','紫玉','从筠',
          '雪海','白筠','灵芙','安莲','惜梅','雪蕾','寄容',
          '秋波','冷云','秋儿','怀菱','亦柏','易槐','怀卉',
          '紫桃','向蕊','易青','千蕊','怜露','灵旋','怀梅',
          '半白','碧安','秋枫','傲丝','春柔','冰岚','雅翠',
          '易白','夜灵','静柔','醉绿','乐蕊','寄蓝','乐彤',
          '迎琴','之亦','雨寒','谷山','凝安','曼萍','碧露',
          '书南','山薇','念珊','芷雁','尔蕾','绮雪','傲萱',
          '新琴','绿蝶','慕旋','怀易','傲云','晓梅','诗菱',
          '灵珊','幻香','若云','如霜','晓晴','灵山','恨桃',
          '梦凝','幻彤','觅波','慕玉','念山','乐桃','语寒',
          '怀海','孤蝶','灵凝','慕蓝','紫青','千兰','孤柔',
          '语曼','问海','寄筠','安露','听晴','冷寒','之翠',
          '碧灵','凡丝','诗波','友芙','寄莲','之蕊','海琴',
          '宛筠','依槐','觅曼','碧菱','半文','访儿','芷珍',
          '绿春','春蝶','怜槐','映露','雨卉'
      ]
      return first_names
    end

  end